package cn.edu.fudan.test;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class ExtractData {
	
	 private static String path = "E:\\PAMAP_Dataset\\PAMAP_Dataset\\Outdoor\\";
	
	public static void main(String[] args) throws IOException{
		String filePath = path +"subject2.dat";
		List<PAMAP> data = new ArrayList<>();
		BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath));
		String s = bufferedReader.readLine();
		while(s != null){
			PAMAP item = new PAMAP();
			String[] elements = s.split(" ");
			item.timestamp = Double.parseDouble(elements[0]);
			item.ID = Integer.parseInt(elements[1].split("\\.")[0]);
			item.x_hand = Double.parseDouble(elements[4]);
			item.y_hand = Double.parseDouble(elements[5]);
			item.z_hand = Double.parseDouble(elements[6]);
//			item.x_chest = Double.parseDouble(elements[24]);
//			item.y_chest = Double.parseDouble(elements[25]);
//			item.z_chest = Double.parseDouble(elements[26]);
//			item.x_ankle = Double.parseDouble(elements[41]);
//			item.y_ankle = Double.parseDouble(elements[42]);
//			item.z_ankle = Double.parseDouble(elements[43]);
			
			item.x_chest = Double.parseDouble(elements[21]);
			item.y_chest = Double.parseDouble(elements[22]);
			item.z_chest = Double.parseDouble(elements[23]);
			item.x_ankle = Double.parseDouble(elements[35]);
			item.y_ankle = Double.parseDouble(elements[36]);
			item.z_ankle = Double.parseDouble(elements[37]);
			data.add(item);
			s = bufferedReader.readLine();
		}
		bufferedReader.close();
		String writePath = path+"subject2_extract";
		FileWriter fWriter = new FileWriter(writePath);
		for(PAMAP i : data){
			fWriter.write(i.ID+" "+i.timestamp+" "+i.x_hand+" "+i.y_hand+" "+i.z_hand+" "+i.x_chest+" "+i.y_chest+" "+i.z_chest+" "+i.x_ankle+" "+i.y_ankle+" "+i.z_ankle+"\r\n");
		}
		fWriter.close();
	}
}
